package de.hwrBerlin.dataMining.view.vImage.figures;

import org.dom4j.Document;
import org.dom4j.Element;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

public class Text extends FilledFigure {
    
    public String text = "";
    
    private String _fontName;
    private int _fontSize;
    
    
    
    public Text(String pText, int pX, int pY) {
        x = pX;
        y = pY;
        text = pText;
    }
    
    
    
    public void paintImage(GC pGc) {
        setValuesToGc(pGc);
        pGc.drawText(text, x, y);
    }
    
    
    
    @Override
    public Rectangle getBounds() {
        //TODO
        return new Rectangle(0, 0, _fontSize, _fontSize * text.length());
    }
    
    
    
    @Override
    public void paintSVG(Document pDocument) {
        Element root = pDocument.getRootElement();
        
        Element oval = root.addElement("text");
        
        setValuesToSVGElement(oval);
        
        oval.addAttribute("x", ""+x);
        oval.addAttribute("y", ""+(y + _fontSize));
        oval.addText(text);
    }
    
    
    
    protected void setValuesToGc(GC pGc) {
        super.setValuesToGc(pGc);
        
        pGc.getFont().dispose();
        pGc.setFont(new Font(null, _fontName, _fontSize, SWT.NONE));
    }
    
    
    
    protected void setValuesToSVGElement(Element pElement) {
        String value = "";

        value += "fill:#" + colorToHex(_foreground) + ";";
        value += "font-family:" + _fontName + ", sans-serif;";
        value += "font-size:" + _fontSize + "px;";
        
        pElement.addAttribute("style", value);
    }
    
    
    
    public void setFontName(String pFontName) {
        _fontName = pFontName;
    }
    
    
    
    public String getFontName() {
        return _fontName;
    }
    
    
    
    public void setFontSize(int pFontSize) {
        _fontSize = pFontSize;
    }
    
    
    
    public int getFontSize() {
        return _fontSize;
    }
    
}
